<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增实体用况')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-interface-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">归属服务：</label>
                <div class="col-sm-8">
                    <select name="appType" id="appType" class="form-control m-b" th:with="type=${@dict.getType('appType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">接口名称：</label>
                <div class="col-sm-8">
                    <input name="interfaceName" id="interfaceName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">接口描述：</label>
                <div class="col-sm-8">
                    <textarea name="interfaceDescription" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">前后类型：</label>
                <div class="col-sm-8">
                    <select name="fbType" id="fbType" class="form-control m-b" th:with="type=${@dict.getType('fbType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">动词：</label>
                <div class="col-sm-8">
                    <select name="operateType" id="operateType" class="form-control m-b" th:with="type=${@dict.getType('operateType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属域：</label>
                <div class="col-sm-8">
                    <select name="domainId" id="domainId" class="form-control m-b" required>
                        <option th:each="dict : ${domainInfoList}" th:text="${dict.domainName}" th:value="${dict.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">归属域对象：</label>
                <div class="col-sm-8">
                    <select name="domainObjectId" id="domainObjectId" class="form-control m-b" required>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否边界：</label>
                <div class="col-sm-8">
                    <select name="isBoundary" id="isBoundary" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否公共：</label>
                <div class="col-sm-8">
                    <select name="isCommon" id="isCommon" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否平台：</label>
                <div class="col-sm-8">
                    <select name="isPlatform" id="isPlatform" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否管理：</label>
                <div class="col-sm-8">
                    <select name="isManage" id="isManage" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required" id="interfaceUrlLabel">接口方法名：</label>
                <div class="col-sm-8">
                    <input name="interfaceUrl" id="interfaceUrl" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">入参DTO名称：</label>
                <div class="col-sm-8">
                    <input name="inParamDtoName" id="inParamDtoName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">出参DTO名称：</label>
                <div class="col-sm-8">
                    <input name="outParamDtoName" id="outParamDtoName" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">操作类型：</label>
                <div class="col-sm-8">
                    <select name="optType" class="form-control m-b" th:with="type=${@dict.getType('optType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="interfaceTypeDiv">
                <label class="col-sm-3 control-label">接口类型：</label>
                <div class="col-sm-8">
                    <select name="interfaceType" id="interfaceType" class="form-control m-b" th:with="type=${@dict.getType('interfaceType')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">特殊接口：</label>
                <div class="col-sm-8">
                    <select name="specialInterface" id="specialInterface" class="form-control m-b" th:with="type=${@dict.getType('specialInterface')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否风险接口：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isPage_' + dict.dictCode}" name="isRisk" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isPage_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否分页：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isPage_' + dict.dictCode}" name="isPage" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isPage_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">总条数：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="total" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">页数：</label>
                <div class="col-sm-8">
                    <input name="page" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">每页大小：</label>
                <div class="col-sm-8">
                    <input name="pageSize" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">非功能需求：</label>
                <div class="col-sm-8">
                    <textarea name="nonFunctionalRequirements" class="form-control"></textarea>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">状态：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">-->
<!--                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">-->
<!--                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">是否返回树形结构：</label>
                <div class="col-sm-8">
                    <select name="isTree" id="isTree" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否定时任务：</label>
                <div class="col-sm-8">
                    <select name="isJob" id="isJob" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="jobDescriptionDiv">
                <label class="col-sm-3 control-label">定时任务描述：</label>
                <div class="col-sm-8">
                    <textarea name="jobDescription" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "interface/interface"
        $("#form-interface-add").validate({
            focusCleanup: true
        });

        if ($("#fbType").val() == '1') {
            $("#interfaceTypeDiv").hide();
        } else {
            $("#interfaceTypeDiv").show();
            if($("#fbType").val() == '2') {
                //$("#appType").val('oms');
                $("#interfaceType").val('2');
            }
        }

        var domainInfoList = [[${domainInfoList}]];
        var domainObjectList = null;
        $("body").on('change', '#domainId', function () {
            var id = $(this).val();
            var config = {
                url: ctx + "domainInfo/domainInfo/domainObjectList?id="+id,
                type: "POST",
                dataType: "json",
                data: null,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                },
                success: function(result) {
                    $.modal.closeLoading();
                    $("#domainObjectId").empty();
                    domainObjectList = null;
                    if (result.data && result.data.length > 0) {
                        domainObjectList = result.data;
                        for (var i=0; i<result.data.length; i++) {
                            $("#domainObjectId").append("<option value='"+result.data[i].id+"'>"+result.data[i].objectName+"</option>");
                        }
                    }
                    changeData()
                }
            };
            $.ajax(config);
        }).on('change', '#domainObjectId', function () {
            changeData();
        }).on('change', '#operateType', function () {
            changeData();
        }).on('change', '#isPlatform', function () {
            changeData();
            var value = $(this).val();
            var fbType = $("#fbType").val();
            if (value == 'Y' && fbType == '2') {
                $("#appType").select2("val", ["poms"]);
            }
        }).on('change', '#appType', function () {
            changeData();
        }).on('change', '#isManage,#isCommon,#isBoundary', function () {
            changeData();
        }).on('change', '#fbType', function () {
            if ($(this).val() != '2') {
                $("#interfaceTypeDiv").hide();
                $("#interfaceUrlLabel").text('接口方法名：');
            } else {
                $("#interfaceTypeDiv").show();
                $("#interfaceUrlLabel").text('接口地址：');
                var isPlatform = $("#isPlatform").val();
                if (isPlatform == 'Y') {
                    $("#appType").select2("val", ["poms"]);
                }
                $("#interfaceType").select2("val", ["2"]);
            }
            changeData();
        });

        $("#domainId").trigger("change");

        function changeData() {
            var domainId = $("#domainId").val();
            var domainObjectId = $("#domainObjectId").val();
            var operateType = $('#operateType').val();
            //var appType = "/" + $('#appType').val();
            var appType = "/oms";
            var isPlatform = $('#isPlatform').val() == "Y" ? "/platform" : "";
            var isManage = $('#isManage').val() == "Y" ? "/mgt" : "";
            var fbType=$("#fbType").val();

            var isObff = $("#appType").val() == "operationbff" ? "/operation" : "";

            $("#interfaceUrl").val('');
            $("#inParamDtoName").val('');
            $("#outParamDtoName").val('');
            var objectEnName = null, domainEnName = null;
            var objectName = null, domainName = null;

            if (domainId) {
                for(var i=0; i < domainInfoList.length; i++) {
                    if (domainId == domainInfoList[i].id) {
                        domainEnName = domainInfoList[i].domainEnName;
                        domainName = domainInfoList[i].domainName;
                        break;
                    }
                }
            } else {
                return;
            }
            if (domainObjectId) {
                for(var i=0; i < domainObjectList.length; i++) {
                    if (domainObjectId == domainObjectList[i].id) {
                        objectEnName = domainObjectList[i].objectEnName;
                        objectName = domainObjectList[i].objectName;
                        break;
                    }
                }
            } else {
                return;
            }
            var isManageZh = $('#isManage').val() == "Y" ? "(管理)" : "";
            var isBoundary=$("#isBoundary").val() == "Y" ? "Border" : "";
            var isBoundaryZh=$("#isBoundary").val() == "Y" ? "(边界)" : "";
            var isCommon=$("#isCommon").val() == "Y" ? "Com" : "";
            var isCommonZh=$("#isCommon").val() == "Y" ? "(公共)" : "";
            var operateTypeName = $("#operateType").find("option:selected").text();
            if (operateTypeName.indexOf('_') >= 0) {
                operateTypeName = operateTypeName.replace("_", objectName);
            } else {
                operateTypeName = operateTypeName + objectName;
            }
            $("#interfaceName").val(operateTypeName + isManageZh + isCommonZh + isBoundaryZh);

            $("#inParamDtoName").val(objectEnName + "ReqDto");
            $("#outParamDtoName").val(objectEnName + "RespDto");
            var tail;
            objectEnName = objectEnName.charAt(0).toUpperCase() + objectEnName.slice(1);
            if (operateType.indexOf('_') >= 0) {
                tail = operateType.replace("_", objectEnName) + isCommon + isBoundary;
            } else {
                tail = operateType + objectEnName + isCommon + isBoundary
            }
            if (fbType == '2') {
                $("#interfaceUrl").val(appType + isPlatform + isObff + isManage + "/" + domainEnName + "/" + tail);
            } else {
                $("#interfaceUrl").val(tail);
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-interface-add').serialize());
            }
        }
    </script>
</body>
</html>